package com.timmy.google_play.holder.detail;

import android.support.v4.view.ViewCompat;
import android.view.View;
import android.view.animation.OvershootInterpolator;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.timmy.google_play.R;
import com.timmy.google_play.base.BaseHolder;
import com.timmy.google_play.bean.ItemBean;
import com.timmy.google_play.conf.Constants;
import com.timmy.google_play.utils.StringUtils;
import com.timmy.google_play.utils.UIUtils;

import butterknife.BindView;
import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by Timmy on 2016/12/14.
 */
public class DetailInfoHolder extends BaseHolder<ItemBean> {
    @BindView(R.id.app_detail_info_iv_icon)
    ImageView mAppDetailInfoIvIcon;
    @BindView(R.id.app_detail_info_tv_name)
    TextView  mAppDetailInfoTvName;
    @BindView(R.id.app_detail_info_rb_star)
    RatingBar mAppDetailInfoRbStar;
    @BindView(R.id.app_detail_info_tv_downloadnum)
    TextView  mAppDetailInfoTvDownloadnum;
    @BindView(R.id.app_detail_info_tv_version)
    TextView  mAppDetailInfoTvVersion;
    @BindView(R.id.app_detail_info_tv_time)
    TextView  mAppDetailInfoTvTime;
    @BindView(R.id.app_detail_info_tv_size)
    TextView  mAppDetailInfoTvSize;

    @Override
    protected View initHolderVIew() {
        View holderView = View.inflate(UIUtils.getContext(), R.layout.item_detail_info, null);

        ViewCompat.animate(holderView).rotationX(360)
                .setInterpolator(new OvershootInterpolator(4))
                .setDuration(1000)
                .start();

        return holderView;
    }

    @Override
    protected void refreshHolderView(ItemBean data) {

        String date        = UIUtils.getResources().getString(R.string.detail_date, data.date);
        String downLoadNum = UIUtils.getResources().getString(R.string.detail_downloadnum, data.downloadNum);
        String size        = UIUtils.getResources().getString(R.string.detail_size, StringUtils.formatFileSize(data.size));
        String version     = UIUtils.getResources().getString(R.string.detail_version, data.version);

        mAppDetailInfoTvDownloadnum.setText(downLoadNum);
        mAppDetailInfoTvVersion.setText(version);
        mAppDetailInfoTvSize.setText(size);
        mAppDetailInfoTvTime.setText(date);

        mAppDetailInfoTvName.setText(data.name);
        mAppDetailInfoRbStar.setRating(data.stars);

        Picasso.with(UIUtils.getContext()).load(Constants.URLS.IMAGEBASEURL + data.iconUrl).into(mAppDetailInfoIvIcon);
    }
}
